{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-11-10T08:31:19.365334Z",
     "start_time": "2025-11-10T08:31:19.359803Z"
    }
   },
   "source": "from sklearn.linear_model import LogisticRegression",
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-10T08:31:19.390479Z",
     "start_time": "2025-11-10T08:31:19.385784Z"
    }
   },
   "cell_type": "code",
   "source": [
    "model = LogisticRegression(\n",
    "    solver='liblinear',\n",
    "    multi_class='multinomial',\n",
    "    max_iter=1000,\n",
    "    class_weight='balanced',\n",
    "    random_state=42,\n",
    "    penalty='l1',\n",
    "    C=1.0\n",
    ")"
   ],
   "id": "a9142e66db2f1402",
   "outputs": [],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-10T08:31:19.406872Z",
     "start_time": "2025-11-10T08:31:19.401613Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# OVR模型\n",
    "# 1. 直接创建 LogisticRegression 模型\n",
    "model_ovr1 = LogisticRegression(multi_class='ovr')"
   ],
   "id": "9056ce524adafa2c",
   "outputs": [],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-10T08:31:19.422658Z",
     "start_time": "2025-11-10T08:31:19.416046Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from sklearn.multiclass import OneVsRestClassifier\n",
    "\n",
    "# 2. 创建 OneVsRestClassifier模型\n",
    "model_ovr2 = OneVsRestClassifier(LogisticRegression())"
   ],
   "id": "e2ebb22906ccbb45",
   "outputs": [],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "# Softmax 逻辑回归\n",
    "model_softmax = LogisticRegression(multi_class='multinomial')"
   ],
   "id": "b52b8c8c5320ed7d"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
